package com.xpgk.mvc.everyDaySession;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jfinal.aop.Before;
import com.jfinal.log.Log;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.xpgk.dto.SplitPage;
import com.xpgk.mvc.base.BaseController;
import com.xpgk.mvc.bentryRegister.Customer;
import com.xpgk.mvc.bstockHandover.StockHandover;
import com.xpgk.mvc.codeSet.Code;

public class EveryDaySessionController extends BaseController {
	
	@SuppressWarnings("unused")
	private static final Log log = Log.getLog(EveryDaySessionController.class);
	
	private  EveryDaySessionService  everyDaySessionService;
	
	public void index(){
	
    	String  userids=getCUserIds();
    	setAttr("organIds", getCUserOrganIds());
		setAttr("userids", userids);
		setAttr("date", new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
		setAttr("lcIds",Code.lc_ids);
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("column", StockHandover.column_organIds);
		String sql = getSqlByBeetl(StockHandover.sqlId_column, param);
		List<StockHandover> shList = StockHandover.dao.find(sql, getCUserOrganIds());
		if(shList!=null && shList.size()>0)
		{
			setAttr("stockHandover", shList.get(0));
		}
		
		
		
		render("BdailyMeeting.html");
	}
	
	/**获取不掉称顾客
	 * 
	 */
	public  void  getBdcCustomer()
	{
		String json = paging(splitPage, TodayMetting.sqlId_splitPageSelectBdc,TodayMetting.sqlId_splitPageFromBdc);
		renderJson(json);
	}
	
	/**获取不到店顾客
	 * 
	 */
	public  void  getBddCustomer()
	{	
		
		String json = paging(splitPage, TodayMetting.sqlId_splitPageSelectBdd,TodayMetting.sqlId_splitPageFromBdd);
		renderJson(json);
	}
	

	/**获取欠款顾客
	 * 
	 */
	public  void  getArrearsCustomer()
	{	
		
		String json = paging(splitPage, TodayMetting.sqlId_splitPageSelectArrears,TodayMetting.sqlId_splitPageFromArrears);
		renderJson(json);
	}
	
	
	
	/**获取新增顾客
	 * 
	 */
	public  void  getXzCustomer()
	{	
		
		String json = paging(splitPage, TodayMetting.sqlId_splitPageSelectXz,TodayMetting.sqlId_splitPageFromXz);
		renderJson(json);
	}
	/**保存日会
	 * 
	 */
	@Before(Tx.class)
	public  void  saveDaySession()
	{	
		
		TodayMetting  tm=getModel(TodayMetting.class);
		String organIds=getCUserOrganIds();
		String userIds=getCUserIds();
		String s=everyDaySessionService.saveDaySession(organIds,userIds,tm);
		renderText(s);
	}
	
	//获取其他信息
	public void getOther(){
		String date=getPara("date");
		String  organids=getCUserOrganIds();
		Map<String, Object> mm= everyDaySessionService.getOther(date,organids);
//		render("BuyProduct.html");
		renderJson(mm);
	}
	
	/**
	 * 顾客欠款详情
	 */
	public void getArrearsCustomerDetail(){
		String json = paging(splitPage, TodayMetting.sqlId_splitPageSelectArrearsDetail,TodayMetting.sqlId_splitPageFromArrearsDetail);
		renderJson(json);
	
	}
	
	
}
